package shuzi.adapter;

import java.util.List;

import shuzi.model.AfterSale;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shuzi.offer.R;

public class AfterSaleAdapter extends BaseAdapter {

	private final LayoutInflater mInflater;
	private List<AfterSale> list;
	private Context context;

	public AfterSaleAdapter(Context context, List<AfterSale> list) {
		this.mInflater = LayoutInflater.from(context);
		this.list = list;
		this.context = context;
	
	}


	public int getCount() {
		// TODO Auto-generated method stub
		return this.list.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.list.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public final class ViewHolder {
		public TextView adress;
		public TextView phoneNumber;
		private final View baseView;

		public ViewHolder(View baseView) {
			this.baseView = baseView;
		}

		public TextView getAdress() {
			return (TextView) baseView.findViewById(R.id.address);
		}

		public void setAdress(TextView adress) {
			this.adress = adress;
		}

		public TextView getPhoneNumber() {
			return (TextView) baseView.findViewById(R.id.phoneNumber);
		}

		public void setPhoneNumber(TextView phoneNumber) {
			this.phoneNumber = phoneNumber;
		}

		

	}
	
	

	public View getView(int position, View convertView, ViewGroup parent) {

	//	Log.v(Database.TAG, position+"");
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = (RelativeLayout) this.mInflater.inflate(
					R.layout.after_item, null);
			holder = new ViewHolder(convertView);
			holder.adress = holder.getAdress();
			holder.phoneNumber = holder.getPhoneNumber();

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();

		}
		
		holder.adress.setText(list.get(position).getAdress());
		holder.phoneNumber.setText(list.get(position).getContactNumber());
		
		return convertView;
	}

}
